home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / POV-Ray 3.0.2 / src / SOURCE / FRAME.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-24  |  34.9 KB  |  1,388 lines  |  [TEXT/CWIE]

  1. /****************************************************************************
  2. *                   frame.h
  3. *
  4. *  This header file is included by all C modules in POV-Ray. It defines all
  5. *  globally-accessible types and constants.
  6. *
  7. *  from Persistence of Vision(tm) Ray Tracer
  8. *  Copyright 1996 Persistence of Vision Team
  9. *---------------------------------------------------------------------------
  10. *  NOTICE: This source code file is provided so that users may experiment
  11. *  with enhancements to POV-Ray and to port the software to platforms other
  12. *  than those supported by the POV-Ray Team.  There are strict rules under
  13. *  which you are permitted to use this file.  The rules are in the file
  14. *  named POVLEGAL.DOC which should be distributed with this file. If
  15. *  POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  16. *  Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  17. *  Forum.  The latest version of POV-Ray may be found there as well.
  18. *
  19. * This program is based on the popular DKB raytracer version 2.12.
  20. * DKBTrace was originally written by David K. Buck.
  21. * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  22. *
  23. * Modified by Andreas Dilger to add PNG file format support 05/09/95
  24. *
  25. *****************************************************************************/
  26.  
  27. #ifndef FRAME_H
  28. #define FRAME_H
  29.  
  30. /* Generic header for all modules */
  31.  
  32. #include <math.h>
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include <limits.h>
  36. #include "config.h"
  37.  
  38.  
  39. /*
  40.  * These two are used if POV is being called from within another program
  41.  * like a GUI interface.
  42.  */
  43. #ifndef MAIN_RETURN_TYPE
  44. #define MAIN_RETURN_TYPE void
  45. #endif
  46.  
  47. #ifndef MAIN_RETURN_STATEMENT
  48. #define MAIN_RETURN_STATEMENT
  49. #endif
  50.  
  51.  
  52. /*
  53.  * Functions that POV calls once per render to do various initializations,
  54.  * in the order that they are normally called.
  55.  */
  56. #ifndef STARTUP_POVRAY  /* First function called in main() for each render */
  57. #define STARTUP_POVRAY
  58. #endif
  59.  
  60. #ifndef PRINT_CREDITS   /* Prints POV-Ray version information banner */
  61. #define PRINT_CREDITS Print_Credits();
  62. #endif
  63.  
  64. #ifndef PRINT_OTHER_CREDITS /* Prints credits for custom POV versions */
  65. #define PRINT_OTHER_CREDITS
  66. #endif
  67.  
  68. /*
  69.  * These read the INI files.  READ_ENV_VAR reads an INI file specified by
  70.  * (usually) the POVINI environment variable instead of the default file.
  71.  * PROCESS_POVRAY_INI reads the INI file from the default location if
  72.  * READ_ENV_VAR wasn't successful.  ALT_WRITE_INI_FILE writes out a new
  73.  * INI file with the values as specified by the used for this render.
  74.  */
  75. #ifndef READ_ENV_VAR
  76. #define READ_ENV_VAR Warning(0.0,"Environment variable not implemented on this platform.\n");
  77. #endif
  78.  
  79. #ifndef PROCESS_POVRAY_INI
  80. #define PROCESS_POVRAY_INI Warning(0.0,"Reading 'povray.ini' not implemented on this platform.\n");
  81. #endif
  82.  
  83. #ifndef ALT_WRITE_INI_FILE
  84. #define ALT_WRITE_INI_FILE
  85. #endif
  86.  
  87. #ifndef FINISH_POVRAY   /* The last call that POV makes to exit */
  88. #define FINISH_POVRAY(n) exit(n);
  89. #endif
  90.  
  91.  
  92. /*
  93.  * Functions that POV calls once per frame to do varios (de)initializations,
  94.  * in the order they are normally called.
  95.  */
  96. #ifndef POV_PRE_RENDER    /* Called just prior to the start of rendering */
  97. #define POV_PRE_RENDER
  98. #endif
  99.  
  100. #ifndef CONFIG_MATH       /* Macro for setting up any special FP options */
  101. #define CONFIG_MATH
  102. #endif
  103.  
  104. #ifndef POV_PRE_PIXEL     /* Called before each pixel is rendered */
  105. #define POV_PRE_PIXEL(x,y,c)
  106. #endif
  107.  
  108. #ifndef POV_POST_PIXEL    /* Called after each pixel is rendered */
  109. #define POV_POST_PIXEL(x,y,c)
  110. #endif
  111.  
  112. #ifndef POV_PRE_SHUTDOWN  /* Called before memory and objects are freed */
  113. #define POV_PRE_SHUTDOWN
  114. #endif
  115.  
  116. #ifndef POV_POST_SHUTDOWN /* Called after memory and objects are freed */
  117. #define POV_POST_SHUTDOWN
  118. #endif
  119.  
  120. #ifndef PRINT_STATS
  121. #define PRINT_STATS(a) Print_Stats(a);
  122. #endif
  123.  
  124.  
  125. /* Various numerical constants that are used in the calculations */
  126. #ifndef EPSILON     /* A small value used to see if a value is nearly zero */
  127. #define EPSILON 1.0e-10
  128. #endif
  129.  
  130. #ifndef HUGE_VAL    /* A very large value, can be considered infinity */
  131. #define HUGE_VAL 1.0e+17
  132. #endif
  133.  
  134. /*
  135.  * If the width of a bounding box in one dimension is greater than
  136.  * the critical length, the bounding box should be set to infinite.
  137.  */
  138.  
  139. #ifndef CRITICAL_LENGTH
  140. #define CRITICAL_LENGTH 1.0e6
  141. #endif
  142.  
  143. #ifndef BOUND_HUGE  /* Maximum lengths of a bounding box. */
  144. #define BOUND_HUGE 2.0e10
  145. #endif
  146.  
  147. /*
  148.  * These values determine the minumum and maximum distances
  149.  * that qualify as ray-object intersections.
  150.  */
  151.  
  152. #define Small_Tolerance 0.001
  153. #define Max_Distance 1.0e7
  154.  
  155.  
  156. #ifndef DBL_FORMAT_STRING
  157. #define DBL_FORMAT_STRING "%lf"
  158. #endif
  159.  
  160. #ifndef DBL
  161. #define DBL double
  162. #endif
  163.  
  164. #ifndef SNGL
  165. #define SNGL float
  166. #endif
  167.  
  168. #ifndef COLC
  169. #define COLC float
  170. #endif
  171.  
  172. #ifndef M_PI
  173. #define M_PI   3.1415926535897932384626
  174. #endif
  175.  
  176. #ifndef M_PI_2
  177. #define M_PI_2 1.57079632679489661923
  178. #endif
  179.  
  180. #ifndef TWO_M_PI
  181. #define TWO_M_PI 6.283185307179586476925286766560
  182. #endif
  183.  
  184. #ifndef M_PI_180
  185. #define M_PI_180 0.01745329251994329576
  186. #endif
  187.  
  188. #ifndef M_PI_360
  189. #define M_PI_360 0.00872664625997164788
  190. #endif
  191.  
  192. /* Some implementations of scanf return 0 on failure rather than EOF */
  193. #ifndef SCANF_EOF
  194. #define SCANF_EOF EOF
  195. #endif
  196.  
  197. /* Get minimum/maximum of two values. */
  198.  
  199. #ifndef min
  200. #define min(x,y) (((x)>(y))?(y):(x))
  201. #endif
  202.  
  203. #ifndef max
  204. #define max(x,y) (((x)<(y))?(y):(x))
  205. #endif
  206.  
  207. /* Get minimum/maximum of three values. */
  208.  
  209. #define max3(x,y,z) (((x)>(y))?(((x)>(z))?(x):(z)):(((y)>(z))?(y):(z)))
  210. #define min3(x,y,z) (((x)<(y))?(((x)<(z))?(x):(z)):(((y)<(z))?(y):(z)))
  211.  
  212. #ifndef labs      /* Absolute value of the long integer x. */
  213. #define labs(x) (long) (((x)<0)?-(x):(x))
  214. #endif
  215.  
  216. #ifndef fabs      /* Absolute value of the double x. */
  217. #define fabs(x) ((x) < 0.0 ? -(x) : (x))
  218. #endif
  219.  
  220.  
  221. /*
  222.  * Whether we want ANSI or K&R function prototypes.  The default gives us
  223.  * ANSI prototypes, and the other option is to define PARAMS to nothing.
  224.  */
  225. #ifndef PARAMS
  226. #define PARAMS(x) x
  227. #endif
  228.  
  229. #ifndef TRUE
  230. #define TRUE 1
  231. #define FALSE 0
  232. #endif
  233.  
  234. #ifndef CONST       /* How to define a local variable - normally 'const' */
  235. #define CONST
  236. #endif
  237.  
  238. #ifndef CDECL
  239. #define CDECL
  240. #endif
  241.  
  242. #ifndef NEW_LINE_STRING
  243. #define NEW_LINE_STRING "\n"
  244. #endif
  245.  
  246. /* If compiler version is undefined, then make it 'u' for unknown */
  247. #ifndef COMPILER_VER
  248. #define COMPILER_VER ".u"
  249. #endif
  250.  
  251. #ifndef QSORT
  252. #define QSORT(a,b,c,d) qsort((a),(b),(c),(d))
  253. #endif
  254.  
  255.  
  256. /*
  257.  * POV_NAME_MAX is for file systems that have a separation of the filename
  258.  * into name.ext.  The POV_NAME_MAX is the name part.  FILE_NAME_LENGTH
  259.  * is the sum of name + extension.
  260.  */
  261. #ifndef POV_NAME_MAX
  262. #define POV_NAME_MAX 8
  263. #endif
  264.  
  265. #ifndef FILE_NAME_LENGTH
  266. #define FILE_NAME_LENGTH 150
  267. #endif
  268.  
  269. #ifndef FILENAME_SEPARATOR
  270. #define FILENAME_SEPARATOR '/'
  271. #endif
  272.  
  273. #ifndef DRIVE_SEPARATOR
  274. #define DRIVE_SEPARATOR ':'
  275. #endif
  276.  
  277. /*
  278.  * Splits a given string into the path and file components using the
  279.  * FILENAME_SEPARATOR and DRIVE_SEPARATOR
  280.  */
  281. #ifndef POV_SPLIT_PATH
  282. #define POV_SPLIT_PATH(s,p,f) POV_Split_Path((s),(p),(f))
  283. #endif
  284.  
  285. /* How to read, write and append to binary files using fopen() */
  286. #ifndef READ_FILE_STRING
  287. #define READ_FILE_STRING "rb"
  288. #endif
  289.  
  290. #ifndef WRITE_FILE_STRING
  291. #define WRITE_FILE_STRING "wb"
  292. #endif
  293.  
  294. #ifndef APPEND_FILE_STRING
  295. #define APPEND_FILE_STRING "ab"
  296. #endif
  297.  
  298. /* How to read, write and append to text files using fopen() */
  299. #ifndef READ_TEXT_FILE_STRING
  300. #define READ_TEXT_FILE_STRING "r"
  301. #endif
  302.  
  303. #ifndef WRITE_TEXT_FILE_STRING
  304. #define WRITE_TEXT_FILE_STRING "w"
  305. #endif
  306.  
  307. #ifndef APPEND_TEXT_FILE_STRING
  308. #define APPEND_TEXT_FILE_STRING "a"
  309. #endif
  310.  
  311. /* The output file format used if the user doesn't specify one */
  312. #ifndef DEFAULT_OUTPUT_FORMAT
  313. #define DEFAULT_OUTPUT_FORMAT   't'
  314. #endif
  315.  
  316. /* System specific image format like BMP for Windows or PICT for Mac */
  317. #ifndef READ_SYS_IMAGE
  318. #define READ_SYS_IMAGE(i,n) Read_Targa_Image((i),(n))
  319. #endif
  320.  
  321. #ifndef GET_SYS_FILE_HANDLE
  322. #define GET_SYS_FILE_HANDLE Get_Targa_File_Handle
  323. #endif
  324.  
  325. #ifndef SYS_DEF_EXT
  326. #define SYS_DEF_EXT ".tga"
  327. #endif
  328.  
  329. /* Functions to delete and rename a file */
  330. #ifndef DELETE_FILE_ERR
  331. #define DELETE_FILE_ERR -1
  332. #endif
  333.  
  334. #ifndef DELETE_FILE
  335. #define DELETE_FILE(name) unlink(name)
  336. #endif
  337.  
  338. #ifndef RENAME_FILE_ERR
  339. #define RENAME_FILE_ERR -1
  340. #endif
  341.  
  342. #ifndef RENAME_FILE
  343. #define RENAME_FILE(orig,new) rename(orig,new)
  344. #endif
  345.  
  346. #ifndef MAX_BUFSIZE  /* The maximum size of the output file buffer */
  347. #define MAX_BUFSIZE INT_MAX
  348. #endif
  349.  
  350.  
  351. /*
  352.  * The TIME macros are used when displaying the rendering time for the user.
  353.  * These are called in such a manner that STOP_TIME can be called multiple
  354.  * times for a givn START_TIME in order to get intermediate TIME_ELAPSED
  355.  * values.  TIME_ELAPSED is often defined as (tstop - tstart).
  356.  */
  357. #ifndef START_TIME
  358. #define START_TIME time(&tstart);     
  359. #endif
  360.  
  361. #ifndef STOP_TIME
  362. #define STOP_TIME  time(&tstop);
  363. #endif
  364.  
  365. #ifndef TIME_ELAPSED
  366. #define TIME_ELAPSED difftime (tstop, tstart);
  367. #endif
  368.  
  369. #ifndef SPLIT_TIME
  370. #define SPLIT_TIME(d,h,m,s) POV_Std_Split_Time ((d),(h),(m),(s))
  371. #endif
  372.  
  373.  
  374. /*
  375.  * The PRECISION_TIMER macros are used in generating histogram images on
  376.  * systems that have very accurate timers (usually in the microsecond range).
  377.  */
  378. #ifndef PRECISION_TIMER_AVAILABLE
  379. #define PRECISION_TIMER_AVAILABLE 0
  380. #endif
  381.  
  382. #ifndef PRECISION_TIMER_INIT  /* Called once to initialize the timer */
  383. #define PRECISION_TIMER_INIT
  384. #endif
  385.  
  386. #ifndef PRECISION_TIMER_START
  387. #define PRECISION_TIMER_START ;
  388. #endif
  389.  
  390. #ifndef PRECISION_TIMER_STOP
  391. #define PRECISION_TIMER_STOP
  392. #endif
  393.  
  394. #ifndef PRECISION_TIMER_COUNT  /* The difference between START and STOP times */
  395. #define PRECISION_TIMER_COUNT 0
  396. #endif
  397.  
  398.  
  399. /*
  400.  * The COOPERATE macros are used on co-operative multi-tasking systems to
  401.  * return control to the GUI or OS.  COOPERATE is the old form, and one
  402.  * or both of COOPERATE_0 and COOPERATE_1 should be defined instead.
  403.  */
  404. #ifdef COOPERATE
  405. #define COOPERATE_0     COOPERATE
  406. #define COOPERATE_1     COOPERATE
  407. #endif
  408.  
  409. #ifndef COOPERATE_0    /* Called less frequently */
  410. #define COOPERATE_0
  411. #endif
  412.  
  413. #ifndef COOPERATE_1    /* Called more frequently */
  414. #define COOPERATE_1
  415. #endif
  416.  
  417.  
  418. /* How to get input from the user */
  419. #ifndef TEST_ABORT
  420. #define TEST_ABORT
  421. #endif
  422.  
  423. #ifndef WAIT_FOR_KEYPRESS
  424. #define WAIT_FOR_KEYPRESS
  425. #else
  426. #define WAIT_FOR_KEYPRESS_EXISTS
  427. #endif
  428.  
  429. #ifndef GET_KEY /* Gets a keystroke from the user without waiting */
  430. #define GET_KEY
  431. #else
  432. #define GET_KEY_EXISTS
  433. #endif
  434.  
  435.  
  436. /*
  437.  * Functions which have POV default replacements, but which can be replaced
  438.  * by system-specific functions.  Care should be taken with the RAND
  439.  * functions, as changing these means your images will render differently.
  440.  */
  441. #ifndef POV_RAND   /* Return a pseudo-random 32-bit value in [0, 2^32-1] */
  442. #define POV_RAND() POV_Std_rand()
  443. #endif
  444.  
  445. #ifndef POV_SRAND  /* Seed the random number generator with the given value */
  446. #define POV_SRAND(i) POV_Std_srand(i)
  447. #endif
  448.  
  449.  
  450. /*
  451.  * Functions that write text for the user to see.  These functions will
  452.  * usually be customized for GUI environments so that POV outputs its
  453.  * messages to a status bar or popup window.
  454.  */
  455. #ifndef POV_BANNER
  456. #define POV_BANNER(s) POV_Std_Banner(s)
  457. #endif
  458.  
  459. #ifndef POV_WARNING
  460. #define POV_WARNING(s) POV_Std_Warning(s)
  461. #endif
  462.  
  463. #ifndef POV_RENDER_INFO
  464. #define POV_RENDER_INFO(s) POV_Std_Render_Info(s)
  465. #endif
  466.  
  467. #ifndef POV_STATUS_INFO
  468. #define POV_STATUS_INFO(s) POV_Std_Status_Info(s)
  469. #endif
  470.  
  471. #ifndef POV_DEBUG_INFO
  472. #define POV_DEBUG_INFO(s) POV_Std_Debug_Info(s)
  473. #endif
  474.  
  475. #ifndef POV_FATAL
  476. #define POV_FATAL(s) POV_Std_Fatal(s)
  477. #endif
  478.  
  479. #ifndef POV_STATISTICS
  480. #define POV_STATISTICS(s) POV_Std_Statistics(s)
  481. #endif
  482.  
  483.  
  484. /*
  485.  * Functions that handle the graphical display preview.  These functions
  486.  * will be customeized for all versions of POV that want to do any sort
  487.  * of rendering preview.  The default functions will create a 80x25 text
  488.  * "rendering" using crude ASCII graphics.
  489.  */
  490. #ifndef POV_DISPLAY_INIT     /* Initializes display for each frame rendered */
  491. #define POV_DISPLAY_INIT(w,h) POV_Std_Display_Init((w),(h));
  492. #endif
  493.  
  494. #ifndef POV_DISPLAY_FINISHED  /* Waits for user input after rendering done */
  495. #define POV_DISPLAY_FINISHED POV_Std_Display_Finished();
  496. #endif
  497.  
  498. #ifndef POV_DISPLAY_CLOSE     /* Closes the display window after each frame */
  499. #define POV_DISPLAY_CLOSE POV_Std_Display_Close();
  500. #endif
  501.  
  502. #ifndef POV_DISPLAY_PLOT      /* Plots a single pixel */
  503. #define POV_DISPLAY_PLOT(x,y,r,g,b,a) POV_Std_Display_Plot((x),(y),(r),(g),(b),(a));
  504. #endif
  505.  
  506. #ifndef POV_DISPLAY_PLOT_RECT  /* Plots a filled rectangle */
  507. #define POV_DISPLAY_PLOT_RECT(x1,x2,y1,y2,r,g,b,a) POV_Std_Display_Plot_Rect((x1),(x2),(y1),(y2),(r),(g),(b),(a));
  508. #endif
  509.  
  510. #ifndef POV_DISPLAY_PLOT_BOX   /* Plots a hollow box */
  511. #define POV_DISPLAY_PLOT_BOX(x1,y1,x2,y2,r,g,b,a) POV_Std_Display_Plot_Box((x1),(y1),(x2),(y2),(r),(g),(b),(a));
  512. #endif
  513.  
  514.  
  515. /* The next two are palette modes, for normal and grayscale display */
  516. #ifndef NORMAL
  517. #define NORMAL '0'
  518. #endif
  519.  
  520. #ifndef GREY
  521. #define GREY   'G'
  522. #endif
  523.  
  524. /*
  525.  * The DEFAULT_DISPLAY_GAMMA is used when there isn't one specified by the
  526.  * user in the POVRAY.INI.  For those systems that are very savvy, this
  527.  * could be a function which returns the current display gamma.  The
  528.  * DEFAULT_ASSUMED_GAMMA should be left alone.
  529.  */
  530. #ifndef DEFAULT_DISPLAY_GAMMA
  531. #define DEFAULT_DISPLAY_GAMMA 2.2
  532. #endif
  533.  
  534. #ifndef DEFAULT_ASSUMED_GAMMA
  535. #define DEFAULT_ASSUMED_GAMMA 1.0
  536. #endif
  537.  
  538.  
  539. /*****************************************************************************
  540.  *
  541.  * MEMIO.C Memory macros
  542.  *
  543.  *****************************************************************************/
  544.  
  545. #ifndef __FILE__
  546. #define __FILE__ ""
  547. #endif
  548.  
  549. #ifndef __LINE__
  550. #define __LINE__ (-1)
  551. #endif
  552.  
  553. /*
  554.  * These functions define macros which do checking for memory allocation,
  555.  * and can also do other things.  Check mem.c before you change them, since
  556.  * they aren't simply replacements for malloc, calloc, realloc, and free.
  557.  */
  558. #ifndef POV_MALLOC
  559. #define POV_MALLOC(size,msg)        pov_malloc ((size), __FILE__, __LINE__, (msg))
  560. #endif
  561.  
  562. #ifndef POV_CALLOC
  563. #define POV_CALLOC(nitems,size,msg) pov_calloc ((nitems), (size), __FILE__, __LINE__, (msg))
  564. #endif
  565.  
  566. #ifndef POV_REALLOC
  567. #define POV_REALLOC(ptr,size,msg)   pov_realloc ((ptr), (size), __FILE__, __LINE__, (msg))
  568. #endif
  569.  
  570. #ifndef POV_FREE
  571. #define POV_FREE(ptr)               pov_free ((void *)(ptr), __FILE__, __LINE__)
  572. #endif
  573.  
  574. /* For those systems that don't have memmove, this can also be pov_memmove */
  575. #ifndef POV_MEMMOVE
  576. #define POV_MEMMOVE                 memmove
  577. #endif
  578.  
  579.  
  580. /*
  581.  * Functions which invoke external programs to do work for POV, generally
  582.  * at the request of the user.
  583.  */
  584. #ifndef POV_SHELLOUT
  585. #define POV_SHELLOUT(string) pov_shellout(string)
  586. #endif
  587.  
  588. #ifndef POV_MAX_CMD_LENGTH
  589. #define POV_MAX_CMD_LENGTH 250
  590. #endif
  591.  
  592. #ifndef POV_SYSTEM
  593. #define POV_SYSTEM(string) system(string)
  594. #endif
  595.  
  596.  
  597. /*****************************************************************************
  598.  *
  599.  * Typedefs that need to be known here.
  600.  *
  601.  *****************************************************************************/
  602.  
  603. typedef struct Object_Struct OBJECT;
  604. typedef struct Ray_Struct RAY;
  605. typedef struct istack_struct ISTACK;
  606. typedef struct istk_entry INTERSECTION;
  607.  
  608.  
  609.  
  610. /*****************************************************************************
  611.  *
  612.  * Scalar, color and vector stuff.
  613.  *
  614.  *****************************************************************************/
  615.  
  616. typedef DBL UV_VECT [2];
  617. typedef DBL VECTOR [3];
  618. typedef DBL MATRIX [4][4];
  619. typedef DBL EXPRESS [5];
  620. typedef COLC COLOUR [5];
  621. typedef COLC RGB [3];
  622. typedef int TOKEN;
  623. typedef int CONSTANT;
  624. typedef short WORD;
  625.  
  626. /* Stuff for bounding boxes. */
  627.  
  628. #define BBOX_VAL SNGL
  629.  
  630. typedef BBOX_VAL BBOX_VECT[3];
  631.  
  632. #define Assign_BBox_Vect(d,s) \
  633. { \
  634.   (d)[X] = (s)[X]; \
  635.   (d)[Y] = (s)[Y]; \
  636.   (d)[Z] = (s)[Z]; \
  637. }
  638.  
  639. #define Make_BBox(BBox, llx, lly, llz, lex, ley, lez) \
  640. { \
  641.   (BBox).Lower_Left[X] = (BBOX_VAL)(llx); \
  642.   (BBox).Lower_Left[Y] = (BBOX_VAL)(lly); \
  643.   (BBox).Lower_Left[Z] = (BBOX_VAL)(llz); \
  644.   (BBox).Lengths[X] = (BBOX_VAL)(lex); \
  645.   (BBox).Lengths[Y] = (BBOX_VAL)(ley); \
  646.   (BBox).Lengths[Z] = (BBOX_VAL)(lez); \
  647. }
  648.  
  649. #define Make_BBox_from_min_max(BBox, mins, maxs) \
  650. { \
  651.   (BBox).Lower_Left[X] = (BBOX_VAL)(mins[X]); \
  652.   (BBox).Lower_Left[Y] = (BBOX_VAL)(mins[Y]); \
  653.   (BBox).Lower_Left[Z] = (BBOX_VAL)(mins[Z]); \
  654.   (BBox).Lengths[X] = (BBOX_VAL)(maxs[X]-mins[X]); \
  655.   (BBox).Lengths[Y] = (BBOX_VAL)(maxs[Y]-mins[Y]); \
  656.   (BBox).Lengths[Z] = (BBOX_VAL)(maxs[Z]-mins[Z]); \
  657. }
  658.  
  659. #define Make_min_max_from_BBox(mins, maxs, BBox) \
  660. { \
  661.   (mins)[X] = (BBox).Lower_Left[X]; \
  662.   (mins)[Y] = (BBox).Lower_Left[Y]; \
  663.   (mins)[Z] = (BBox).Lower_Left[Z]; \
  664.   (maxs)[X] = (mins)[X] + (BBox).Lengths[X]; \
  665.   (maxs)[Y] = (mins)[Y] + (BBox).Lengths[Y]; \
  666.   (maxs)[Z] = (mins)[Z] + (BBox).Lengths[Z]; \
  667. }
  668.  
  669. /* Stuff for SNGL vectors. */
  670.  
  671. typedef SNGL SNGL_VECT[3];
  672.  
  673. #define Assign_SNGL_Vect(d,s) \
  674. { \
  675.   (d)[X] = (s)[X]; \
  676.   (d)[Y] = (s)[Y]; \
  677.   (d)[Z] = (s)[Z]; \
  678. }
  679.  
  680.  
  681. /* Vector array elements. */
  682. #define U 0
  683. #define V 1
  684.  
  685. #define X 0
  686. #define Y 1
  687. #define Z 2
  688. #define T 3
  689.  
  690.  
  691. /* Colour array elements. */
  692.  
  693. #define RED    0
  694. #define GREEN  1
  695. #define BLUE   2
  696. #define FILTER 3
  697. #define TRANSM 4
  698.  
  699. /* Macros to manipulate scalars, vectors, and colors. */
  700.  
  701. #define Destroy_Float(x)    if ((x)!=NULL) POV_FREE(x)
  702.  
  703. #define Assign_Vector(d,s)  memcpy((d),(s),sizeof(VECTOR))
  704. #define Destroy_Vector(x)   if ((x)!=NULL) POV_FREE(x)
  705.  
  706. #define Assign_UV_Vect(d,s) memcpy((d),(s),sizeof(UV_VECT))
  707. #define Destroy_UV_Vect(x)  if ((x)!=NULL) POV_FREE(x)
  708.  
  709. #define Assign_Colour(d,s)  memcpy((d),(s),sizeof(COLOUR))
  710. #define Make_Colour(c,r,g,b) {(c)[RED]=(r);(c)[GREEN]=(g);(c)[BLUE]=(b);(c)[FILTER]=0.0;(c)[TRANSM]=0.0;}
  711. #define Make_ColourA(c,r,g,b,a,t) {(c)[RED]=(r);(c)[GREEN]=(g);(c)[BLUE]=(b);(c)[FILTER]=(a);(c)[TRANSM]=t;}
  712. #define Make_Vector(v,a,b,c) { (v)[X]=(a);(v)[Y]=(b);(v)[Z]=(c); }
  713. #define Destroy_Colour(x) if ((x)!=NULL) POV_FREE(x)
  714. #define Make_RGB(c,r,g,b) {(c)[RED]=(r);(c)[GREEN]=(g);(c)[BLUE]=(b);}
  715.  
  716.  
  717.  
  718. /*****************************************************************************
  719.  *
  720.  * Hi-resolution counter.
  721.  *
  722.  *****************************************************************************/
  723.  
  724. /* Define counter resolution. */
  725.  
  726. #define LOW_RESOLUTION  1
  727. #define HIGH_RESOLUTION 2
  728.  
  729. #define COUNTER_RESOLUTION HIGH_RESOLUTION
  730.  
  731. #if COUNTER_RESOLUTION == HIGH_RESOLUTION
  732.  
  733. /* 64bit counter. */
  734.  
  735. typedef struct Counter_Struct COUNTER;
  736.  
  737. struct Counter_Struct
  738. {
  739.   unsigned long high, low;
  740. };
  741.  
  742. #define DBL_Counter(x)     ( (x).low + Sqr(65536.0)*(DBL)(x).high )
  743. #define Long_To_Counter(i,x) { (x).low = i; (x).high = 0; }
  744. #define Init_Counter(x)     { (x).high = (x).low = 0L; }
  745. #define Test_Zero_Counter(x) (((x).low == 0L) && ((x).high == 0L))
  746. #define Increase_Counter(x) { if ((++(x).low) == 0L) { (x).high++; } }
  747. #define Add_Counter(x, a, b) \
  748. { \
  749.   (x).low = (a).low + (b).low; \
  750.   \
  751.   if (((x).low < (a).low) || ((x).low < (b).low)) \
  752.   { \
  753.     /* add with carry */ \
  754.     (x).high = (a).high + (b).high + 1; \
  755.   } \
  756.   else \
  757.   { \
  758.     /* add without carry */ \
  759.     (x).high = (a).high + (b).high; \
  760.   } \
  761. }
  762.  
  763. #else
  764.  
  765. /* 32bit counter. */
  766.  
  767. typedef unsigned long COUNTER;
  768.  
  769. #define DBL_Counter(x)     ( (DBL)(x) )
  770. #define Long_To_Counter(i,x) { (x) = i; }
  771. #define Init_Counter(x)      { (x) = 0L; }
  772. #define Increase_Counter(x)  { (x)++; }
  773. #define Test_Zero_Counter(x) ((x) == 0L)
  774. #define Add_Counter(x, a, b) { (x) = (a) + (b); }
  775.  
  776. #endif
  777.  
  778.  
  779.  
  780. /*****************************************************************************
  781.  *
  782.  * Bounding box stuff (see also BOUND.H).
  783.  *
  784.  *****************************************************************************/
  785.  
  786. typedef struct Bounding_Box_Struct BBOX;
  787.  
  788. struct Bounding_Box_Struct
  789. {
  790.   BBOX_VECT Lower_Left, Lengths;
  791. };
  792.  
  793.  
  794.  
  795. /*****************************************************************************
  796.  *
  797.  * Transformation stuff.
  798.  *
  799.  *****************************************************************************/
  800.  
  801. typedef struct Transform_Struct TRANSFORM;
  802.  
  803. struct Transform_Struct
  804. {
  805.   MATRIX matrix;
  806.   MATRIX inverse;
  807. };
  808.  
  809. #define Destroy_Transform(x) if ((x)!=NULL) POV_FREE(x)
  810.  
  811.  
  812.  
  813. /*****************************************************************************
  814.  *
  815.  * Color map stuff.
  816.  *
  817.  *****************************************************************************/
  818.  
  819. #define MAX_BLEND_MAP_ENTRIES 256
  820.  
  821. typedef struct Blend_Map_Entry BLEND_MAP_ENTRY;
  822. typedef struct Blend_Map_Struct BLEND_MAP;
  823. typedef struct Pattern_Struct TPATTERN;
  824. typedef struct Texture_Struct TEXTURE;
  825. typedef struct Pigment_Struct PIGMENT;
  826. typedef struct Tnormal_Struct TNORMAL;
  827. typedef struct Finish_Struct FINISH;
  828. typedef struct Turb_Struct TURB;
  829. typedef struct Warps_Struct WARP;
  830. typedef struct Halo_Struct HALO;
  831.  
  832. struct Blend_Map_Entry
  833. {
  834.   SNGL value;
  835.   unsigned char Same;
  836.   union
  837.   {
  838.    COLOUR Colour;
  839.    PIGMENT *Pigment;
  840.    TNORMAL *Tnormal;
  841.    TEXTURE *Texture;
  842.    UV_VECT Point_Slope;
  843.   } Vals;
  844. };
  845.  
  846. struct Blend_Map_Struct
  847. {
  848.   short Number_Of_Entries, Transparency_Flag, Type;
  849.   long  Users;
  850.   BLEND_MAP_ENTRY *Blend_Map_Entries;
  851. };
  852.  
  853. #define Make_Blend_Map_Entry(entry,v,s,r,g,b,a,t) \
  854. { \
  855.   (entry).value = (v); \
  856.   (entry).Same = (s); \
  857.   Make_ColourA((entry).Vals.Colour, r, g, b, a, t); \
  858. }
  859.  
  860.  
  861. /*****************************************************************************
  862.  *
  863.  * IFF file stuff.
  864.  *
  865.  *****************************************************************************/
  866.  
  867. #ifndef IFF_SWITCH_CAST
  868. #define IFF_SWITCH_CAST (int)
  869. #endif
  870.  
  871. typedef struct Image_Colour_Struct IMAGE_COLOUR;
  872.  
  873. typedef struct Image_Line_Struct IMAGE_LINE;
  874.  
  875. struct Image_Colour_Struct
  876. {
  877.   unsigned short Red, Green, Blue, Filter, Transmit;
  878. };
  879.  
  880. struct Image_Line_Struct
  881. {
  882.   unsigned char *red, *green, *blue, *transm;
  883. };
  884.  
  885.  
  886.  
  887. /*****************************************************************************
  888.  *
  889.  * Image stuff.
  890.  *
  891.  *****************************************************************************/
  892.  
  893. /* Legal image attributes. */
  894.  
  895. #define NO_FILE         0x0000
  896. #define GIF_FILE        0x0001
  897. #define POT_FILE        0x0002
  898. #define SYS_FILE        0x0004
  899. #define IFF_FILE        0x0008
  900. #define TGA_FILE        0x0010
  901. #define GRAD_FILE       0x0020
  902. #define PGM_FILE        0x0040
  903. #define PPM_FILE        0x0080
  904. #define PNG_FILE        0x0100
  905.  
  906. #define IMAGE_FTYPE     0x0400
  907. #define HF_FTYPE        0x0800
  908. #define HIST_FTYPE      0x1000
  909. #define GRAY_FTYPE      0x2000
  910. #define NORMAL_FTYPE    0x4000
  911. #define MATERIAL_FTYPE  0x8000
  912.  
  913. /* Image types. */
  914.  
  915. #define IMAGE_FILE    IMAGE_FTYPE+GIF_FILE+SYS_FILE+IFF_FILE+GRAD_FILE+TGA_FILE+PGM_FILE+PPM_FILE+PNG_FILE
  916. #define NORMAL_FILE   NORMAL_FTYPE+GIF_FILE+SYS_FILE+IFF_FILE+GRAD_FILE+TGA_FILE+PGM_FILE+PPM_FILE+PNG_FILE
  917. #define MATERIAL_FILE MATERIAL_FTYPE+GIF_FILE+SYS_FILE+IFF_FILE+GRAD_FILE+TGA_FILE+PGM_FILE+PPM_FILE+PNG_FILE
  918. #define HF_FILE       HF_FTYPE+GIF_FILE+POT_FILE+TGA_FILE+PGM_FILE+PPM_FILE+PNG_FILE
  919.  
  920. typedef struct Image_Struct IMAGE;
  921.  
  922. struct Image_Struct
  923. {
  924.   int References; /* Keeps track of number of pointers to this structure */
  925.   int Map_Type;
  926.   int File_Type;
  927.   int Image_Type; /* What this image is being used for */
  928.   int Interpolation_Type;
  929.   short Once_Flag;
  930.   short Use_Colour_Flag;
  931.   VECTOR Gradient;
  932.   SNGL width, height;
  933.   int iwidth, iheight;
  934.   short Colour_Map_Size;
  935.   IMAGE_COLOUR *Colour_Map;
  936.   union
  937.   {
  938.     IMAGE_LINE *rgb_lines;
  939.     unsigned char **map_lines;
  940.   } data;
  941. };
  942.  
  943. #define PIGMENT_TYPE  0
  944. #define NORMAL_TYPE   1
  945. #define PATTERN_TYPE  2
  946. #define TEXTURE_TYPE  4
  947. #define COLOUR_TYPE   5
  948. #define SLOPE_TYPE    6
  949.  
  950.  
  951. /*****************************************************************************
  952.  *
  953.  * Pigment, Tnormal, Finish, Halo, Texture & Warps stuff.
  954.  *
  955.  *****************************************************************************/
  956.  
  957. #define TPATTERN_FIELDS       \
  958.   unsigned short Type, Wave_Type, Flags; \
  959.   int References;             \
  960.   SNGL Frequency, Phase;      \
  961.   WARP *Warps;                \
  962.   TPATTERN *Next;             \
  963.   BLEND_MAP *Blend_Map;       \
  964.   union {                     \
  965.    IMAGE *Image;              \
  966.    VECTOR Gradient;           \
  967.    SNGL Agate_Turb_Scale;     \
  968.    short Num_of_Waves;        \
  969.    short Iterations;          \
  970.    short Arms;                \
  971.    struct {SNGL Mortar; VECTOR Size;} Brick; \
  972.    struct {SNGL Control0, Control1; } Quilted;   \
  973.   } Vals;
  974.  
  975.  
  976. struct Pattern_Struct
  977. {
  978.   TPATTERN_FIELDS
  979. };
  980.  
  981. struct Pigment_Struct
  982. {
  983.   TPATTERN_FIELDS
  984.   COLOUR Colour; 
  985. };
  986.  
  987. struct Tnormal_Struct
  988. {
  989.   TPATTERN_FIELDS
  990.   SNGL Amount;
  991. };
  992.  
  993. #define TEXTURE_FIELDS \
  994.   TPATTERN_FIELDS      \
  995.   TEXTURE *Next_Material;
  996.  
  997. struct Texture_Struct
  998. {
  999.   TEXTURE_FIELDS
  1000.   PIGMENT *Pigment;
  1001.   TNORMAL *Tnormal;
  1002.   FINISH *Finish;
  1003.   HALO *Halo;                                   /* zss 10/03/95 */
  1004.   TEXTURE *Materials;
  1005.   int Num_Of_Mats;
  1006.  
  1007. };
  1008.  
  1009. struct Finish_Struct
  1010. {
  1011.   SNGL Diffuse, Brilliance, Index_Of_Refraction;
  1012.   SNGL Refraction, Specular, Roughness, Phong, Phong_Size;
  1013.   SNGL Irid, Irid_Film_Thickness, Irid_Turb;
  1014.   SNGL Crand, Metallic, Caustics;
  1015.   SNGL Fade_Distance, Fade_Power;
  1016.   RGB Ambient, Reflection;
  1017. };
  1018.  
  1019. struct Halo_Struct
  1020. {
  1021.   char Type, Flags;
  1022.   char Dust_Type;
  1023.   char Mapping_Type;          /* Geometry of density distributions        */
  1024.   char Rendering_Type;        /* Type of rendering algorithm to be used   */
  1025.   TURB *Turb;                 /* Turbulence transformation                */
  1026.   BLEND_MAP *Blend_Map;       /* Color map to be used                     */
  1027.   TRANSFORM *Trans;           /* Local transformation to be used          */
  1028.   TRANSFORM *Container_Trans; /* Transformation applied to container only */
  1029.   DBL Max_Value, Exponent;    /* Parameters of density functions          */
  1030.   DBL Eccentricity;           /* Eccentricity of Heyney-Greenstein fn.    */
  1031.   DBL Samples;                /* Number of samples to be used             */
  1032.   DBL Jitter;                 /* Amount of jitter                         */
  1033.   int AA_Level;               /* Max. level of subdivision                */
  1034.   DBL AA_Threshold;           /* Threshold to kick in supersampling       */
  1035.   HALO *Next_Halo;            /* Next halo description of this texture    */
  1036.   DBL Frequency, Phase;
  1037. };
  1038.  
  1039. #define WARP_FIELDS unsigned short Warp_Type; WARP *Next_Warp;
  1040.  
  1041. struct Warps_Struct
  1042. {
  1043.   WARP_FIELDS
  1044. };
  1045.  
  1046. struct Turb_Struct
  1047. {
  1048.   WARP_FIELDS
  1049.   VECTOR Turbulence;
  1050.   int Octaves;
  1051.   SNGL Lambda, Omega;
  1052. };
  1053.  
  1054. #define Destroy_Finish(x) if ((x)!=NULL) POV_FREE(x)
  1055.  
  1056.  
  1057.  
  1058.  
  1059. /*****************************************************************************
  1060.  *
  1061.  * Object stuff (see also OBJECTS.H and primitive include files).
  1062.  *
  1063.  *****************************************************************************/
  1064.  
  1065. #define All_Intersections(x,y,z) ((*((x)->Methods->All_Intersections_Method)) (x,y,z))
  1066. #define Inside(x,y) ((*((y)->Methods->Inside_Method)) (x,y))
  1067. #define Normal(x,y,z) ((*((y)->Methods->Normal_Method)) (x,y,z))
  1068. #define Copy(x) ((*((x)->Methods->Copy_Method)) (x))
  1069. #define Translate(x,y,z) ((*((x)->Methods->Translate_Method)) (x,y,z))
  1070. #define Scale(x,y,z) ((*((x)->Methods->Scale_Method)) (x,y,z))
  1071. #define Rotate(x,y,z) ((*((x)->Methods->Rotate_Method)) (x,y,z))
  1072. #define Transform(x,y) ((*((x)->Methods->Transform_Method)) (x,y))
  1073. #define Invert(x) ((*((x)->Methods->Invert_Method)) (x))
  1074. #define Destroy(x) ((*((x)->Methods->Destroy_Method)) (x))
  1075.  
  1076. typedef struct Method_Struct METHODS;
  1077.  
  1078. typedef int (*ALL_INTERSECTIONS_METHOD)PARAMS((OBJECT *, RAY *, ISTACK *));
  1079. typedef int (*INSIDE_METHOD)PARAMS((VECTOR , OBJECT *));
  1080. typedef void (*NORMAL_METHOD)PARAMS((VECTOR, OBJECT *, INTERSECTION *));
  1081. typedef void *(*COPY_METHOD)PARAMS((OBJECT *));
  1082. typedef void (*TRANSLATE_METHOD)PARAMS((OBJECT *, VECTOR, TRANSFORM *));
  1083. typedef void (*ROTATE_METHOD)PARAMS((OBJECT *, VECTOR, TRANSFORM *));
  1084. typedef void (*SCALE_METHOD)PARAMS((OBJECT *, VECTOR, TRANSFORM *));
  1085. typedef void (*TRANSFORM_METHOD)PARAMS((OBJECT *, TRANSFORM *));
  1086. typedef void (*INVERT_METHOD)PARAMS((OBJECT *));
  1087. typedef void (*DESTROY_METHOD)PARAMS((OBJECT *));
  1088.  
  1089. /* These fields are common to all objects. */
  1090.  
  1091. #define OBJECT_FIELDS   \
  1092.   METHODS *Methods;     \
  1093.   int Type;             \
  1094.   OBJECT *Sibling;      \
  1095.   TEXTURE *Texture;     \
  1096.   OBJECT *Bound;        \
  1097.   OBJECT *Clip;         \
  1098.   BBOX BBox;            \
  1099.   unsigned short Flags;
  1100.  
  1101. /* These fields are common to all compound objects */
  1102.  
  1103. #define COMPOUND_FIELDS \
  1104.   OBJECT_FIELDS          \
  1105.   OBJECT *Children;
  1106.  
  1107. #define INIT_OBJECT_FIELDS(o,t,m) \
  1108.   o->Type    = t;                 \
  1109.   o->Methods = m;                 \
  1110.   o->Sibling = NULL;              \
  1111.   o->Texture = NULL;              \
  1112.   o->Bound   = NULL;              \
  1113.   o->Clip    = NULL;              \
  1114.   o->Flags   = 0;                 \
  1115.   Make_BBox(o->BBox, -BOUND_HUGE/2.0, -BOUND_HUGE/2.0, -BOUND_HUGE/2.0, \
  1116.     BOUND_HUGE, BOUND_HUGE, BOUND_HUGE);
  1117.  
  1118. struct Method_Struct
  1119. {
  1120.   ALL_INTERSECTIONS_METHOD All_Intersections_Method;
  1121.   INSIDE_METHOD Inside_Method;
  1122.   NORMAL_METHOD Normal_Method;
  1123.   COPY_METHOD Copy_Method;
  1124.   TRANSLATE_METHOD Translate_Method;
  1125.   ROTATE_METHOD Rotate_Method;
  1126.   SCALE_METHOD Scale_Method;
  1127.   TRANSFORM_METHOD Transform_Method;
  1128.   INVERT_METHOD Invert_Method;
  1129.   DESTROY_METHOD Destroy_Method;
  1130. };
  1131.  
  1132. /* This is an abstract structure that is never actually used.
  1133.    All other objects are descendents of this primative type */
  1134.  
  1135. struct Object_Struct
  1136. {
  1137.   OBJECT_FIELDS
  1138. };
  1139.  
  1140.  
  1141.  
  1142. /*****************************************************************************
  1143.  *
  1144.  * Intersection stack stuff.
  1145.  *
  1146.  *****************************************************************************/
  1147.  
  1148. struct istk_entry
  1149. {
  1150.    DBL Depth;
  1151.    VECTOR IPoint;
  1152.    VECTOR INormal;
  1153.    OBJECT *Object;
  1154. /*
  1155.  *  [DB 8/94]
  1156.  *
  1157.  * Pass additional values from the intersection function to other functions
  1158.  * (normal calculation). 2 ints and 2 DBLS seem enough.
  1159.  */
  1160.    int i1, i2;
  1161.    DBL d1, d2;
  1162.  /* Arbitrary pointer that can be passed. */
  1163.    void *Pointer;
  1164. };
  1165.  
  1166. struct istack_struct
  1167. {
  1168.    struct istack_struct *next;
  1169.    struct istk_entry *istack;
  1170.    unsigned int top_entry;
  1171. };
  1172.  
  1173. #define itop(i) (i->istack[i->top_entry])
  1174.  
  1175. /* Macros to push intersection onto stack. */
  1176.  
  1177. #define push_entry(d,v,o,i)                  \
  1178.   itop(i).Depth  = d;                        \
  1179.   itop(i).Object = o;                        \
  1180.   Assign_Vector(itop(i).IPoint,v);           \
  1181.   incstack(i);
  1182.  
  1183. #define push_normal_entry(d,v,n,o,i)         \
  1184.   itop(i).Depth  = d;                        \
  1185.   itop(i).Object = o;                        \
  1186.   Assign_Vector(itop(i).IPoint,v);           \
  1187.   Assign_Vector(itop(i).INormal,n);          \
  1188.   incstack(i);
  1189.  
  1190. /* Use these macros to push additional parameters onto the stack. [DB 8/94] */
  1191.  
  1192. #define push_entry_pointer(d,v,o,a,i)        \
  1193.   itop(i).Depth  = d;                        \
  1194.   itop(i).Object = o;                        \
  1195.   itop(i).Pointer = (void *)(a);             \
  1196.   Assign_Vector(itop(i).IPoint,v);           \
  1197.   incstack(i);
  1198.  
  1199. #define push_entry_i1(d,v,o,a,i)             \
  1200.   itop(i).Depth  = d;                        \
  1201.   itop(i).Object = o;                        \
  1202.   itop(i).i1 = a;                            \
  1203.   Assign_Vector(itop(i).IPoint,v);           \
  1204.   incstack(i);
  1205.  
  1206. #define push_entry_d1(d,v,o,a,i)             \
  1207.   itop(i).Depth  = d;                        \
  1208.   itop(i).Object = o;                        \
  1209.   itop(i).d1 = a;                            \
  1210.   Assign_Vector(itop(i).IPoint,v);           \
  1211.   incstack(i);
  1212.  
  1213. #define push_entry_i1_i2(d,v,o,a,b,i)        \
  1214.   itop(i).Depth  = d;                        \
  1215.   itop(i).Object = o;                        \
  1216.   itop(i).i1 = a;                            \
  1217.   itop(i).i2 = b;                            \
  1218.   Assign_Vector(itop(i).IPoint,v);           \
  1219.   incstack(i);
  1220.  
  1221. #define push_entry_i1_d1(d,v,o,a,b,i)        \
  1222.   itop(i).Depth  = d;                        \
  1223.   itop(i).Object = o;                        \
  1224.   itop(i).i1 = a;                            \
  1225.   itop(i).d1 = b;                            \
  1226.   Assign_Vector(itop(i).IPoint,v);           \
  1227.   incstack(i);
  1228.  
  1229. #define push_entry_i1_i2_d1(d,v,o,a,b,c,i)   \
  1230.   itop(i).Depth  = d;                        \
  1231.   itop(i).Object = o;                        \
  1232.   itop(i).i1 = a;                            \
  1233.   itop(i).i2 = b;                            \
  1234.   itop(i).d1 = c;                            \
  1235.   Assign_Vector(itop(i).IPoint,v);           \
  1236.   incstack(i);
  1237.  
  1238. #define push_copy(i,e) itop(i)= *e; incstack(i);
  1239. #define pop_entry(i) (i->top_entry > 0)?&(i->istack[--i->top_entry]):NULL
  1240.  
  1241.  
  1242.  
  1243. /*****************************************************************************
  1244.  *
  1245.  * Ray stuff (see also RAY.H).
  1246.  *
  1247.  *****************************************************************************/
  1248.  
  1249. #define MAX_CONTAINING_OBJECTS 100
  1250.  
  1251. struct Ray_Struct
  1252. {
  1253.   VECTOR Initial;
  1254.   VECTOR Direction;
  1255.   int Containing_Index;
  1256.   TEXTURE *Containing_Textures[MAX_CONTAINING_OBJECTS];
  1257.   OBJECT  *Containing_Objects[MAX_CONTAINING_OBJECTS];
  1258.   DBL Containing_IORs[MAX_CONTAINING_OBJECTS];
  1259. };
  1260.  
  1261.  
  1262. /*****************************************************************************
  1263.  *
  1264.  * Frame tracking information
  1265.  *
  1266.  *****************************************************************************/
  1267. typedef enum
  1268. {
  1269.   FT_SINGLE_FRAME,
  1270.   FT_MULTIPLE_FRAME
  1271. } FRAMETYPE;
  1272.  
  1273. #define INT_VALUE_UNSET (-1)
  1274. #define DBL_VALUE_UNSET (-1.0)
  1275.  
  1276. typedef struct
  1277. {
  1278.   FRAMETYPE FrameType;
  1279.   DBL Clock_Value;      /* May change between frames of an animation */
  1280.   int FrameNumber;      /* May change between frames of an animation */
  1281.  
  1282.   int InitialFrame;
  1283.   DBL InitialClock;
  1284.  
  1285.   int FinalFrame;
  1286.   int FrameNumWidth;
  1287.   DBL FinalClock;
  1288.  
  1289.   int SubsetStartFrame;
  1290.   DBL SubsetStartPercent;
  1291.   int SubsetEndFrame;
  1292.   DBL SubsetEndPercent;
  1293.   
  1294.   unsigned Field_Render_Flag;
  1295.   unsigned Odd_Field_Flag;
  1296. } FRAMESEQ;
  1297.  
  1298.  
  1299. /*****************************************************************************
  1300.  *
  1301.  * Miscellaneous stuff.
  1302.  *
  1303.  *****************************************************************************/
  1304.  
  1305. typedef struct Chunk_Header_Struct CHUNK_HEADER;
  1306. typedef struct Data_File_Struct DATA_FILE;
  1307. typedef struct complex_block complex;
  1308. typedef struct file_handle_struct FILE_HANDLE;
  1309.  
  1310. struct Reserved_Word_Struct
  1311. {
  1312.   TOKEN Token_Number;
  1313.   char *Token_Name;
  1314. };
  1315.  
  1316. /* Here's where you dump the information on the current token (fm. PARSE.C) */
  1317.  
  1318. struct Token_Struct
  1319. {
  1320.   TOKEN Token_Id;
  1321.   TOKEN Function_Id;
  1322.   int Token_Line_No;
  1323.   char *Token_String;
  1324.   DBL Token_Float;
  1325.   TOKEN Begin_Id;
  1326.   int Constant_Index;
  1327.   int Unget_Token, End_Of_File;
  1328.   char *Filename, *Constant_Data;
  1329. };
  1330.  
  1331. struct Constant_Struct
  1332. {
  1333.   int Identifier_Number;
  1334.   CONSTANT Constant_Type;
  1335.   char *Constant_Data;
  1336. };
  1337.  
  1338. struct Chunk_Header_Struct
  1339. {
  1340.   long name;
  1341.   long size;
  1342. };
  1343.  
  1344. struct Data_File_Struct
  1345. {
  1346.   FILE *File;
  1347.   char *Filename;
  1348.   int Line_Number;
  1349. };
  1350.  
  1351. struct complex_block
  1352. {
  1353.   DBL r, c;
  1354. };
  1355.  
  1356. #define READ_MODE 0
  1357. #define WRITE_MODE 1
  1358. #define APPEND_MODE 2
  1359.  
  1360. struct file_handle_struct
  1361. {
  1362.   char *filename;
  1363.   int mode;
  1364.   int width, height;
  1365.   int buffer_size;
  1366.   char *buffer;
  1367.   FILE *file;
  1368.   int file_type;  /* What format the output file is */
  1369.   int  (*Open_File_p) PARAMS((struct file_handle_struct *handle,
  1370.     char *name, int *width, int *height, int buffer_size, int mode));
  1371.   void (*Write_Line_p) PARAMS((struct file_handle_struct *handle,
  1372.     COLOUR *line_data, int line_number));
  1373.   int (*Read_Line_p) PARAMS((struct file_handle_struct *handle,
  1374.     COLOUR *line_data, int *line_number));
  1375.   void (*Read_Image_p) PARAMS((IMAGE *Image, char *filename));
  1376.   void (*Close_File_p) PARAMS((struct file_handle_struct *handle));
  1377. };
  1378.  
  1379. #define Open_File(h,n,wd,ht,sz,m) ((*((h)->Open_File_p)) (h,n,wd,ht,sz,m))
  1380. #define Write_Line(h,l,n) ((*((h)->Write_Line_p)) (h, l, n))
  1381. #define Read_Line(h,l,n) ((*((h)->Read_Line_p)) (h, l, n))
  1382. #define Read_Image(h,i) ((*((h)->Read_Image_p)) (h, i))
  1383. #define Close_File(h) ((*((h)->Close_File_p)) (h))
  1384.  
  1385.  
  1386.  
  1387. #endif
  1388.